package com.http;

import android.os.AsyncTask;

import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;

/**
 * 
 * @ClassName:SimpleStringTask
 * @Description:TODO简单获取字符串结果的接口
 * @author zhuw
 * @date 2013-9-22 下午11:12:25
 */
public class SimpleStringTask extends AsyncTask<Void, Void, ResultString> {
	public static interface CallBack extends NetWorkCallBack {
		public abstract void procResult(String resCode,String  data);

	}

	CallBack callback;
	String path;//访问数据路径
	String resCode;//区分路径
	public SimpleStringTask(CallBack callback,String path,String resCode) {
		super();
		this.callback = callback;
		this.path=path;
		this.resCode=resCode;
	}

	@Override
	protected ResultString doInBackground(Void... params) {
		ResultString data = null;
		try {
			ResEntity re=NetConUtil.sendGetRequestEntity(path);
			if(re.code==ResEntity.S_OK){
			    data= new ResultString(CommonData.H_FLAG_SUCCESS, null,re.jsonStr);
			}else if(re.code==ResEntity.S_FAILED){
				
				  data= new ResultString(CommonData.H_FLAG_ERROR, "code:"+re.code+"    "+re.jsonStr, null);
				
			}else{
				  data= new ResultString(CommonData.H_FLAG_ERROR, "code:"+re.code+ErrorCode.ERROR_MSG, null);
			}
		} catch (Exception e) {
			data= new ResultString(CommonData.H_FLAG_ERROR, ErrorCode.ERROR_MSG, null);
			e.printStackTrace();

		}
		return data;
	}

	@Override
	protected void onPostExecute(ResultString result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callback.procResult(resCode,result.result);

		} else {
			callback.procError(result.msg);
		}

	}
}
